export default class AddProperty2UnitOwnerOnUseAbilityState {

    static config: { [id: string]: { addGold?: number, addLumber?: number, addFood?: number } } = {}

    constructor() {


        let triggerHandle = CreateTrigger();
        TriggerRegisterAnyUnitEventBJ(triggerHandle, EVENT_PLAYER_UNIT_SPELL_EFFECT);
        TriggerAddAction(triggerHandle, this.action);
    }


    action(this: void) {
        let spellAbilityIdStr = id2string(GetSpellAbilityId());
        let cfgData = AddProperty2UnitOwnerOnUseAbilityState.config[spellAbilityIdStr];
        if (cfgData) {
            let unit = GetTriggerUnit();
            let player = GetOwningPlayer(unit);
            if (cfgData.addGold) {
                AdjustPlayerStateBJ(cfgData.addGold, player, PLAYER_STATE_RESOURCE_GOLD);
            }
            if (cfgData.addLumber) {
                AdjustPlayerStateBJ(cfgData.addLumber, player, PLAYER_STATE_RESOURCE_LUMBER);
            }
            if (cfgData.addFood) {
                AdjustPlayerStateBJ(cfgData.addFood, player, PLAYER_STATE_RESOURCE_FOOD_CAP);
            }


        }


    }

}

